# -*- coding: utf-8 -*-

from django.conf import settings as django_settings
from pms.models import PrivateMessage
def settings(request):
    """Returns the settings object"""
    return {'settings':django_settings}
def request(r):
    """Returns the request"""
    return {'request':r}

def private_messages(request):
    """Returns the numer of the user's unread PMs as context variable, "unread_pms", 
        and the latest unread PM as "latest_pm" """
    
    if request.user.is_anonymous():
        return {}
    pms = PrivateMessage.objects.get_user_pms(request.user)
    num_pms = pms.count()
    latest_pm = pms[0] if num_pms else None
    
    return {'unread_pms':num_pms, 'latest_pm':latest_pm}